package com.zrar.ak.gkpt.controller.record;

import com.zrar.ak.gkpt.model.vo.UserVO;
import com.zrar.ak.gkpt.service.impl.record.BusinessOntractInfoService;
import com.zrar.ak.gkpt.service.record.IBusinessSchemeInfoService;
import com.zrar.ak.gkpt.service.user.IUserService;
import com.zrar.ak.gkpt.util.FormDataParameter;
import com.zrar.ak.gkpt.util.JsonPageResult;
import com.zrar.ak.gkpt.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: SchemeRefinementInfoController
 * @Description: 方案细化Controller层
 * @Author: CaoTao
 * @Create: 2020/04/04
 */
@RestController
@RequestMapping("/scheme")
@Api(tags = "方案细化信息相关接口")
public class BusinessSchemeInfoController {

    @Autowired
    private IBusinessSchemeInfoService schemeInfoService;

    @Autowired
    private IUserService userService;

    @RequestMapping(value = "basicInfoSave", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "保存方案细化基本信息", httpMethod = "POST", notes = "方案细化基本信息")
    public JsonResult schemeBasicInfoSave(HttpServletRequest request,
                                             @ApiParam(name = "formDataParameter", value = "方案细化基本信息数据参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = schemeInfoService.schemeBasicInfoSave(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "Save", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "保存方案细化详细信息", httpMethod = "POST", notes = "保存方案细化详细信息")
    public JsonResult schemeInfoSave(HttpServletRequest request,
                                          @ApiParam(name = "formDataParameter", value = "方案细化详细信息数据参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = schemeInfoService.schemeInfoSave(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "delete", method = RequestMethod.DELETE, produces = {"application/json;charset=utf-8"})
    @ApiOperation(value = "删除方案细化信息", httpMethod = "DELETE", notes = "删除方案细化信息")
    public JsonResult schemeInfoDeleteById(HttpServletRequest request,
                                        @ApiParam(name = "basicsId", value = "基础信息表主键") @RequestParam(value ="basicsId") String basicsId) {
        JsonResult jsonResult = new JsonResult();
        jsonResult = schemeInfoService.deleteSchemeByBasicsId(jsonResult,basicsId);
        return jsonResult;
    }

    @RequestMapping(value = "query", method = RequestMethod.GET, produces = {"application/json;charset=utf-8"})
    @ApiOperation(value = "查看方案细化信息", httpMethod = "GET", notes = "查看方案细化信息")
    public JsonResult schemeInfoGetById(@ApiParam(name = "id", value = "主键id") @RequestParam(value ="id") String id) {
        JsonResult jsonResult = new JsonResult();
        jsonResult = schemeInfoService.querySchemeByUnitId(jsonResult,id);
        return jsonResult;
    }

    @RequestMapping(value = "update", method = RequestMethod.PUT, produces = {"application/json;charset=utf-8"})
    @ApiOperation(value = "更新方案细化信息", httpMethod = "PUT", notes = "更新方案细化信息")
    public JsonResult schemeInfoUpdate(HttpServletRequest request, @ApiParam(name = "formDataParameter", value = "更新方案细化信息参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = schemeInfoService.schemeTerminalInfoUpdate(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "list", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "获取方案细化信息列表-分页查询和条件查询", httpMethod = "GET", notes = "获取方案细化信息列表-分页查询和条件查询")
    public JsonPageResult getAccountInfoList(HttpServletRequest request,
                                             @ApiParam(name = "currentPage", value = "当前页") @RequestParam int currentPage,
                                             @ApiParam(name = "pageSize", value = "每页条数限制") @RequestParam int pageSize,
                                             @ApiParam(name = "unitName", value = "建设单位名称(模糊查询)") @RequestParam(value = "unitName", required = false) String unitName) {
        JsonPageResult jsonResult = new JsonPageResult();
        jsonResult = schemeInfoService.getSchemeInfoList(jsonResult, currentPage, pageSize, unitName);
        return jsonResult;
    }

}
